%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note Figure A2 uses the dataset "data_figureA2.csv" generated from STATA
% file 0.clean_data.do. You need to run this .do file first.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.

%Set the path below to the current folder in your directories
% Include your directories to the 'figures' sub-folder under the replication folder below: e.g. /Users/litang/Library/CloudStorage/Dropbox/RCT_Housing_new/data/replication/figures
path(path,'INCLUDE DIRECTORY OF THE "FIGURES" SUB-FOLDER UNDER THE REPLICATION FOLDER')

x0=10;
y0=10;
width=1200;
height=750;
set(gcf,'position',[x0,y0,width,height])

filename = 'data_figureA2.csv';
mDATA = readtable(filename); % First row is a header
Font_size = 10;  
Line_width = 1.5;
%% script treatment group
mDATA1 = mDATA(mDATA.group == 1,:);

subplot(3,3,1)
set(gcf,'position',[x0,y0,width,height])

histogram(mDATA1.script_evaluation,5,'BinLimits',[-2.5,2.5],'BinWidth',0.5, 'Normalization','probability', 'FaceColor', "red")
title('{FOMC script treatment group}', '{Wordings/script signal evaluation }', 'FontWeight', 'bold')
ylabel('Fraction')
xlabel('Evaluation')
ylim([0 0.4])
ax = gca;
ax.XTick = [-1.75 -0.75 0.25 1.25 2.25];
ax.XTickLabel = '';
myLabels = { '-2', '-1', '0', '1', '2'; 
    'Very', 'Somewhat', 'Neutral', 'Somewhat', 'Very';
    'negative', 'negative', ' ', 'positive', 'positive' };

for i = 1:length(myLabels)
    text(ax.XTick(i), ax.YLim(1), sprintf('%s\n%s\n%s', myLabels{:,i}), ...
        'horizontalalignment', 'center', 'verticalalignment', 'top');    
end
ax.XLabel.String = sprintf('\n\n\n%s', '');

set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'off';

%% audio treatment group
mDATA2 = mDATA(mDATA.group == 2,:);
subplot(3,3,4)
histogram(mDATA2.script_evaluation,5,'BinLimits',[-2.5,2.5],'BinWidth',0.5, 'Normalization','probability', 'FaceColor', "red")
title('{FOMC audio treatment group}', '{Wordings/script signal evaluation }', 'FontWeight', 'bold')
ylabel('Fraction')
xlabel('Evaluation')
ylim([0 0.4])
ax = gca;
ax.XTick = [-1.75 -0.75 0.25 1.25 2.25];
ax.XTickLabel = '';
myLabels = { '-2', '-1', '0', '1', '2'; 
    'Very', 'Somewhat', 'Neutral', 'Somewhat', 'Very';
    'negative', 'negative', ' ', 'positive', 'positive' };

for i = 1:length(myLabels)
    text(ax.XTick(i), ax.YLim(1), sprintf('%s\n%s\n%s', myLabels{:,i}), ...
        'horizontalalignment', 'center', 'verticalalignment', 'top');    
end
ax.XLabel.String = sprintf('\n\n\n%s', '');

set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'off';


subplot(3,3,5)
histogram(mDATA2.voice_evaluation,5,'BinLimits',[-2.5,2.5],'BinWidth',0.5, 'Normalization','probability', 'FaceColor', "green")
title('{Voice tones signal evaluation}')
ylabel('Fraction')
xlabel('Evaluation')
ylim([0 0.5])
ax = gca;
ax.XTick = [-1.75 -0.75 0.25 1.25 2.25];
ax.XTickLabel = '';
myLabels = { '-2', '-1', '0', '1', '2'; 
    'Very', 'Somewhat', 'Neutral', 'Somewhat', 'Very';
    'negative', 'negative', ' ', 'positive', 'positive' };

for i = 1:length(myLabels)
    text(ax.XTick(i), ax.YLim(1), sprintf('%s\n%s\n%s', myLabels{:,i}), ...
        'horizontalalignment', 'center', 'verticalalignment', 'top');    
end
ax.XLabel.String = sprintf('\n\n\n%s', '');

set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'off';


%% video treatment group
mDATA3 = mDATA(mDATA.group == 3,:);
subplot(3,3,7)
histogram(mDATA3.script_evaluation,5,'BinLimits',[-2.5,2.5],'BinWidth',0.5, 'Normalization','probability', 'FaceColor', "red")
title('{FOMC video treatment group}', '{Wordings/script signal evaluation }', 'FontWeight', 'bold')
ylabel('Fraction')
xlabel('Evaluation')
ylim([0 0.4])
ax = gca;
ax.XTick = [-1.75 -0.75 0.25 1.25 2.25];
ax.XTickLabel = '';
myLabels = { '-2', '-1', '0', '1', '2'; 
    'Very', 'Somewhat', 'Neutral', 'Somewhat', 'Very';
    'negative', 'negative', ' ', 'positive', 'positive' };

for i = 1:length(myLabels)
    text(ax.XTick(i), ax.YLim(1), sprintf('%s\n%s\n%s', myLabels{:,i}), ...
        'horizontalalignment', 'center', 'verticalalignment', 'top');    
end
ax.XLabel.String = sprintf('\n\n\n%s', '');

set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'off';

subplot(3,3,8)
set(gcf,'position',[x0,y0,width,height])
histogram(mDATA3.voice_evaluation,5,'BinLimits',[-2.5,2.5],'BinWidth',0.5, 'Normalization','probability', 'FaceColor', "green")
title('{Voice tones signal evaluation}')
ylabel('Fraction')
xlabel('Evaluation')
ylim([0 0.5])
ax = gca;
ax.XTick = [-1.75 -0.75 0.25 1.25 2.25];
ax.XTickLabel = '';
myLabels = { '-2', '-1', '0', '1', '2'; 
    'Very', 'Somewhat', 'Neutral', 'Somewhat', 'Very';
    'negative', 'negative', ' ', 'positive', 'positive' };

for i = 1:length(myLabels)
    text(ax.XTick(i), ax.YLim(1), sprintf('%s\n%s\n%s', myLabels{:,i}), ...
        'horizontalalignment', 'center', 'verticalalignment', 'top');    
end
ax.XLabel.String = sprintf('\n\n\n%s', '');

set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'off';

subplot(3,3,9)
set(gcf,'position',[x0,y0,width,height])
histogram(mDATA3.face_evaluation,5,'BinLimits',[-2.5,2.5],'BinWidth',0.5, 'Normalization','probability', 'FaceColor', "blue")
title('{Body languages signal evaluation}')
ylabel('Fraction')
xlabel('Evaluation')
ylim([0 0.6])
ax = gca;
ax.XTick = [-1.75 -0.75 0.25 1.25 2.25];
ax.XTickLabel = '';
myLabels = { '-2', '-1', '0', '1', '2'; 
    'Very', 'Somewhat', 'Neutral', 'Somewhat', 'Very';
    'negative', 'negative', ' ', 'positive', 'positive' };

for i = 1:length(myLabels)
    text(ax.XTick(i), ax.YLim(1), sprintf('%s\n%s\n%s', myLabels{:,i}), ...
        'horizontalalignment', 'center', 'verticalalignment', 'top');    
end
ax.XLabel.String = sprintf('\n\n\n%s', '');

set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'off';

dpi =70;
width_in = width / dpi;
height_in = height / dpi;
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [width_in, height_in]);
set(gcf, 'PaperPosition', [0, 0, width_in, height_in]);
set(gcf, 'PaperPositionMode', 'manual');

saveas(gcf,'Figure_A2.pdf','pdf')



